package com.itheima.service.omsService.impl;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.commons.PageBean;
import com.itheima.domain.db.oms.OmsOrderReturnReason;
import com.itheima.mapper.omsMapper.OrderReturnReasonMapper;
import com.itheima.service.omsService.OrderReturnReasonService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author DogeGuo
 */
@DubboService
public class OrderReturnReasonServiceImpl implements OrderReturnReasonService {
    @Autowired
    OrderReturnReasonMapper mapper;

    /**
     * 分页查询退货原因
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageBean pageReturnReason(Integer pageNum, Integer pageSize) {
        IPage<OmsOrderReturnReason> page = new Page<>(pageNum, pageSize);

        mapper.selectPage(page, new LambdaQueryWrapper<>());

        PageBean<OmsOrderReturnReason> pageBean = new PageBean<>(page);
        return pageBean;
    }

    /**
     * 添加退货原因
     *
     * @param omsOrderReturnReason
     */
    @Override
    public void addReturnReason(OmsOrderReturnReason omsOrderReturnReason) {
        mapper.insert(omsOrderReturnReason);
    }

    /**
     * 批量删除退货原因
     *
     * @param ids
     */
    @Override
    public void deleteReturnReason(Integer[] ids) {
        for (Integer id : ids) {
            mapper.deleteById(id);
        }
    }

    /**
     * 修改退货原因启用状态
     *
     * @param ids
     * @param status
     */
    @Override
    public void updateStatus(Integer ids, Integer status) {
        OmsOrderReturnReason omsOrderReturnReason = new OmsOrderReturnReason();
        omsOrderReturnReason.setId(Convert.toLong(ids));
        omsOrderReturnReason.setStatus(status);
        mapper.updateById(omsOrderReturnReason);
    }

    /**
     * 获取单个退货原因详情信息
     *
     * @param id
     * @return
     */
    @Override
    public OmsOrderReturnReason getInfoById(Integer id) {
        return mapper.selectById(id);
    }

    /**
     * 修改退货原因
     *
     * @param omsOrderReturnReason
     */
    @Override
    public void updateInfo(OmsOrderReturnReason omsOrderReturnReason) {
        mapper.updateById(omsOrderReturnReason);
    }
}
